#ifndef TTGIPSPROTOCOL_H
#define TTGIPSPROTOCOL_H

#include <QObject>
#include <QStringList>
#include "cpackagecrc.h"

class TTGIpsProtocol : public QObject
{
    Q_OBJECT
public:
    explicit TTGIpsProtocol(QObject *parent = 0);

    static void ipSwapTobigEndian(char *source,char *dest);

    static QByteArray phyStringToBytes(QString phyAddr);
    static QByteArray groupStringToBytes(QString gAddr);

    static int second_round_encry(unsigned char *send,int length,unsigned char *encrybuffer);
    static int second_round_decry(unsigned char *recv, int length, unsigned char *decrybuffer);
    static int ipad_data_decry(unsigned char *cemi_data, int size, unsigned char *decode_buf) ;

    static unsigned short getCmdCode(QByteArray oriData);

    QByteArray generateEncryPassword(char* pass = NULL);
    QByteArray decryPassword(QByteArray oriData);

    void setIpsPassword(QString pass);
    QByteArray boardcastPackage();
    QByteArray searchIpPackage(unsigned int ip);
    QByteArray devIpChange(unsigned int ipInt);
    QByteArray binFileHand();
    QByteArray binFileTansfer(char total,char index,QByteArray contextData);
    QByteArray passwordInitPackage(QByteArray pass);

    QByteArray filterPhyAddrPackage(short cmd,QStringList *addList,char canPass,short total);
    QByteArray filterGrpAddrPackage(short cmd, QStringList *addList, char canPass,short total);
    QByteArray filterIpPackage(QStringList *addList,char canPass,short total);

    QByteArray devPassChangePackage(QByteArray newPsw);

    QByteArray devSetIpadUser(int scmd, QByteArray user);
    QByteArray devSetIpadPass(int scmd,QByteArray newPsw);
    QByteArray devSetIpadPort(int scmd,QString port);
    QByteArray devSetIpadIp(QString ip);
    QByteArray devSetIpadNetwork(QByteArray mac, unsigned int mask, unsigned int gateway);
    QByteArray devReadIpadNetwork();

signals:

public slots:

private:
    CPackageCRC *_packCRC;

    //0xAA	0x55	长度-2byte	密码区-7byte	命令码-2byte
    QByteArray msgHeader();
    void setPackageSize(char *pdata, int size);

    unsigned char _password[6];
    unsigned char _random;
};

#endif // TTGIPSPROTOCOL_H
